package com.lksoft.bz.action;

import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;

import com.lksoft.bz.Bz;
import com.lksoft.bz.StitchPattern;

public class NewAction extends AbstractAction {
private static final long serialVersionUID = 6607987594348135371L;

	private Bz bz;
	
	/**
	 * @param bz The program
	 * @throws IOException 
	 */
	public NewAction(Bz bz, String iconPath) throws IOException{
		super("", new ImageIcon(ImageIO.read(Bz.class.getResourceAsStream(iconPath)).getScaledInstance(32, 32, Image.SCALE_SMOOTH)));
		this.bz = bz;
		
		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
		putValue(MNEMONIC_KEY, KeyEvent.VK_N);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// Save if unsaved
		if( bz.askForSave() ){
			bz.setStitchPattern( new StitchPattern(), null );
		}
	}

}
